﻿using GpgCore.Products;

namespace GpgCore.GameWorld
{
    public class Citizens
    {
        public City OwnCity;
        public long Population = 100000;
        public int WorkersCount
        {
            get
            {
                return (int) (Population*0.7); //TODO: has to be replaced with some smart indicator of workable population
            }
        }
        public double Money;
        public PeopleNeedsManager NeedsManager;

        public Citizens(City city)
        {
            OwnCity = city;
            NeedsManager = new PeopleNeedsManager();
        }

        public void Morning()
        {
            OwnCity.Exchanges[ProductType.Employees].OpenPositionWithProduct(WorkersCount, this);
        
            //shopping
            foreach (var need in NeedsManager.Needs.Values)
            {
                var sum = need.TotalNeedPercent*Money;
                OwnCity.Exchanges[need.ProductType].OpenPositionWithMoney(sum, this);
                Money -= sum;
            }
        }
        public void Evening()
        {
            Money += OwnCity.Exchanges[ProductType.Employees].GetMyMoney(this);

            //shopping
            foreach (var need in NeedsManager.Needs.Values)
            {
                //buying products
                var prod = OwnCity.Exchanges[need.ProductType].GetMyProduct(this);
                need.Satisfact(Population != 0 ? prod / Population : 0);
            
                //population reaction
                Population += (long)((-0.75+need.TotalSatisfaction)*need.SatisfactionInfluence*Population);
            }

            NeedsManager.CalcValues();
        }
    }
}
